// CController 层（控制器层）是应用程序的重要组成部分，负责处理客户端的请求并返回相应的响应
const { UNAUTHORIZATION } = require("../config/error");
const { PRIVATE_KEY, PUBLIC_KEY } = require("../config/screct");
const jwt = require("jsonwebtoken");
class LoginController {
  // 签发令牌
  sign(ctx, next) {
    const { name, id } = ctx.user;
    const token = jwt.sign({ id, name }, PRIVATE_KEY, {
      expiresIn: 24 * 60 * 60 * 30,
      algorithm: "RS256",
    });

    ctx.body = { id, name, token };
  }

  test(ctx, next) {
    ctx.body = "验证通过";
  }
}
module.exports = new LoginController();

/* 

{
   "name":"admin123",
   "password":"admin123"
}
*/
